package domain;

import java.util.HashSet;
import java.util.Set;

public class Contact {

	private int idContact;
	private String firstName;
	private String lastName;
	private String email;
	private Set<ContactGroup> books;
	private Set<PhoneNumber> phones;

	private Address address;

	public Contact(String firstName, String lastName, String email,
			Address address, Set<ContactGroup> books, Set<PhoneNumber> phones) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
		this.address = address;
		this.books = books;
		this.phones = phones;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public Contact() {

		books = new HashSet<ContactGroup>();
		phones = new HashSet<PhoneNumber>();
	}

	public Set<PhoneNumber> getPhones() {
		return phones;
	}

	public void setPhones(Set<PhoneNumber> phones) {
		this.phones = phones;
		for (PhoneNumber phone : phones)
			if (phone != null)
				phone.setContact(this);
	}

	public Set<ContactGroup> getBooks() {
		return books;
	}

	public void setBooks(Set<ContactGroup> books) {
		// int size = this.books.size();
		// Set<ContactGroup> groups = new HashSet<ContactGroup>();
		// for (ContactGroup cgroup : books)
		// if (cgroup != null) {
		// // if (size > 0) {
		// // for (ContactGroup cg : getBooks()) {
		// // if (!cg.getGroupName().equals(cgroup.getGroupName())) {
		// // cgroup.getContacts().add(this);
		// // groups.add(cgroup);
		// // }
		// // }
		// // } else {
		// // cgroup.getContacts().add(this);
		// groups.add(cgroup);
		// // }
		// }
		this.books.addAll(books);
	}

	public int getIdContact() {
		return idContact;
	}

	private void setIdContact(int id) {
		this.idContact = id;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firsttName) {
		this.firstName = firsttName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String toString() {
		return "Contact First name= " + getFirstName() + "\nLast name = "
				+ getLastName() + "\n Email = " + getEmail();
	}
}
